package ru.artyushov.fingers.core.io;

import ru.artyushov.fingers.core.BinarizationStrategy;
import ru.artyushov.fingers.core.FingerprintReader;
import ru.artyushov.fingers.core.data.Fingerprint;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

public class FingerprintReaderImpl implements FingerprintReader{

    private final BinarizationStrategy binarizationStrategy;

    public FingerprintReaderImpl(BinarizationStrategy binarizationStrategy) {
        this.binarizationStrategy = binarizationStrategy;
    }

    @Override
    public Fingerprint readFrom(InputStream is) throws IOException {
        BufferedImage image = ImageIO.read(is);
        return binarizationStrategy.toFingerprint(image);
    }
}
